define(["plugins/router", "durandal/app", "knockout"], function (router, app, ko) {
    var routes = [
        //默认路由
        {
            route: ["", "home"],
            title: "主页",
            moduleId: "home/index",
            nav: true,
        },
        {
            route: "hello-world",
            title: "Hello World",
            moduleId: "hello-world/index",
            nav: true,
        },
        {
            route: "counter",
            title: "Counter",
            moduleId: "counter/index",
            nav: true,
        },
    ];

    return {
        router: router,
        app: app,
        activate: function () {
            return router
                .map(routes)
                .buildNavigationModel()
                .mapUnknownRoutes("404pages/index", "not-found")
                .activate();
        },
        getRootRouter: function () {
            var rootRouter = ko.utils.arrayFilter(
                router.navigationModel(),
                function (route) {
                    return route.parentHash === undefined;
                }
            );
            return rootRouter;
        },
        getChildRouter: function (parentHash) {
            var childRouter = ko.utils.arrayFilter(
                router.navigationModel(),
                function (route) {
                    return "#" + route.parentHash == parentHash;
                }
            );
            return childRouter;
        },
    };
});
